﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace KingerRobot.MexicoSailunMDC.SpiService;

public class POTcmGtSpecRepositories : IPOTcmGtSpecRepositories
{
    /// <summary>
    /// 写入实体数据
    /// </summary>
    /// <param name="entity">博文实体类</param>
    /// <returns>插入个数 插入成功为1</returns>
    public int Add(POTcmGtSpec entity)
    {
        var _db = Db.Default;
        return _db.TcmGtSpecs.Insert(entity);
    }

    /// <summary>
    /// 批量插入实体
    /// </summary>
    /// <param name="listEntity">实体集合</param>
    /// <returns>影响行数</returns>
    public int Add(IEnumerable<POTcmGtSpec> listEntity)
    {
        var _db = Db.Default;
        _db.TcmGtSpecs.AddRange(listEntity);
        int insertedCount = _db.SaveChanges();
        return insertedCount;
    }

    /// <summary>
    /// 待条件更新所有数据
    /// </summary>
    /// <param name="whereExpression"></param>
    /// <param name="entity"></param>
    /// <returns></returns>
    public int Update(Expression<Func<POTcmGtSpec, bool>> whereExpression, POTcmGtSpec entity)
    {
        var _db = Db.Default;
        return _db.TcmGtSpecs.Where(whereExpression).Update(new POTcmGtSpec()
        {
            SPEC_ID = entity.SPEC_ID,
            TcmNo = entity.TcmNo,
            TcmDesc = entity.TcmDesc,
            TcmDir = entity.TcmDir,
            TcmSpec = entity.TcmSpec,
            TcmSpecDesc = entity.TcmSpecDesc,
            TbmSpec = entity.TbmSpec,
            TbmSpecDesc = entity.TbmSpecDesc,
            TbmSpecVer = entity.TbmSpecVer,
            TbmPs = entity.TbmPs,
            TcmAngle = entity.TcmAngle,
            RegDt = entity.RegDt,
            RcvFlag = entity.RcvFlag,
            TaskType = entity.TaskType,
            TcmHeight = entity.TcmHeight,
            Turnover = entity.Turnover,
            ID = entity.ID,
            Taskcode = entity.Taskcode,
            ExecResult = entity.ExecResult,
            UPDATE = entity.UPDATE,
        });
    }

    /// <summary>
    /// 查询第一条数据
    /// </summary>
    /// <param name="whereExpression"></param>
    /// <returns></returns>
    public POTcmGtSpec First(Expression<Func<POTcmGtSpec, bool>> whereExpression)
    {
        var _db = Db.Default;
        if (whereExpression == null) return null;
        return _db.TcmGtSpecs.Where(whereExpression).FirstOrDefault();
    }
}
